package com.game.modular.gameGm;

import com.game.comment.core.ResponseResult;
import com.game.modular.game.playerAssets.domain.PlayerHero;
import com.game.modular.game.playerAssets.domain.PlayerBag;
import com.game.modular.game.playerAssets.domain.PlayerSkill;
import com.game.modular.game.playerAssets.service.PlayerBagServiceImpl;
import com.game.modular.game.playerAssets.service.PlayerHeroServiceImpl;
import com.game.modular.game.playerAssets.service.PlayerSkillServiceImpl;
import com.game.modular.gameCore.cultivate.domain.CoreHero;
import com.game.modular.gameCore.cultivate.domain.CoreSkill;
import com.game.modular.gameCore.cultivate.service.impl.CoreHeroServiceImpl;
import com.game.modular.gameCore.cultivate.service.impl.CoreSkillServiceImpl;
import com.game.modular.gameGm.vo.GMActionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


@Api(tags = "GM指令")
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("/GMAct")
public class GMAction {
    private final CoreSkillServiceImpl coreSkillServiceImpl;
    private PlayerHeroServiceImpl playerHeroService;
    private CoreHeroServiceImpl coreHeroServiceImpl;
    private PlayerBagServiceImpl playerBagService;
    private PlayerSkillServiceImpl playerSkillService;

    @ApiOperation(value = "获取所有武将可转化为信物")
    @PostMapping("/obtainAllHero")
    public ResponseResult<List<PlayerHero>> obtainAllHero(@RequestBody GMActionVo.obtainAllHero playerGet) {
        List<CoreHero> coreHeroes = coreHeroServiceImpl.listCache();
        List<PlayerHero> accountHeroes = new ArrayList<>();
        for (CoreHero coreHero : coreHeroes) {
            accountHeroes.add(playerHeroService.obtainHero(playerGet.getUid(), coreHero.getId(), 1));
        }
        return ResponseResult.success("获取所有武将成功", accountHeroes);
    }

    @ApiOperation(value = "获取物品")
    @PostMapping("/obtainIOneWIngots")
    public ResponseResult<List<PlayerBag>> obtainIOneWIngots(@RequestBody GMActionVo.obtainIOneWIngots playerGet) {
        playerBagService.obtainBackpackItems(playerGet.getUid(), Long.valueOf(playerGet.getNum()), Long.valueOf(playerGet.getCorePropId()));
        return ResponseResult.success("成功获取获取");
    }

    @ApiOperation(value = "获取技能")
    @PostMapping("/obtainSkill")
    public ResponseResult<PlayerSkill> obtainSkill(@RequestBody GMActionVo.obtainSkill obtainSkill) {
        return ResponseResult.success("成功获取获取战法技能",
                playerSkillService.obtainSkill(
                        obtainSkill.getUid(),
                        obtainSkill.getSkillId(),
                        obtainSkill.getNum()
                )
        );
    }

    @ApiOperation(value = "获取所有技能")
    @PostMapping("/obtainAllSkill")
    public ResponseResult<List<PlayerSkill>> obtainAllSkill(@RequestBody GMActionVo.obtainAllSkill obtainAllSkill) {
        List<CoreSkill> list = coreSkillServiceImpl.list().stream().filter(item->item.getId()>68).collect(Collectors.toList());
        return ResponseResult.success("成功获取获取战法技能",
                list.stream()
                        .map(playerSkill -> playerSkillService.obtainSkill(
                                obtainAllSkill.getUid(),
                                playerSkill.getId(),
                                obtainAllSkill.getNum())
                        )
                        .collect(Collectors.toList())
        );
    }
}
